/*java jdk 1.7+
# -*- coding: utf-8 -
'''
Created on 2020年05月10日
@author: zxyong 13738196011
'''*/

package com.zxy.common;

import java.net.Socket;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttTopic;

import com.zxy.business.Ope_DB_Cent;
import com.zxy.comport.ComDev;
import com.zxy.model.T_DB_CONFIG;
import com.zxy.model.T_PROC_INPARAM;
import com.zxy.model.T_PROC_NAME;
import com.zxy.model.T_PROC_OUTPARAM;
import com.zxy.model.T_PROC_RETURN;
import com.zxy.model.T_SUB_POWER;
import com.zxy.model.T_SUB_SYS;
import com.zxy.model.T_SUB_USER;
import com.zxy.model.T_SUB_USERPOWER;
import com.zxy.model.z_code_element;

public class Com_Para
{
	// 获取子级设备数据信息超时间
	public static int								iTimeCount2					= 0;
	// 本设备服务端口
	public static String							AccSocketPort				= "8085";
	// 实例
	public static Com_Para							instance					= null;
	// 子业务系统数据库配置集
	public static Hashtable<String, T_DB_CONFIG>	htDb						= new Hashtable<String, T_DB_CONFIG>();;
	// 有效session集
	public static Hashtable<String, Object[]>		htSession					= null;
	// LoginCode集
	public static Hashtable<String, String>			htLoginCode					= null;
	// 路径
	public static String							zxyPath						= "/";
	// 相对路径
	public static String							ApplicationPath				= Com_Fun.GetAbsPath();
	// 平台访问函数名
	public static String							Inf_Name					= "CenterData";
	// web文件后缀
	public static String[]							web_Name					=
	{ ".html", ".js", ".css", ".jpg", ".gif", ".png", ".svg", ".eot", ".ttf",
			".woff2", ".woff", ".ico", "map", "json" };
	// 本设备唯一编码
	public static String							Child_Code					= "";
	// 访问父级设备IP
	public static String							ServerIP					= "";
	// 访问父级设备端口
	public static int								ServerPort					= 8090;
	// 是否子级设备 0否 1是
	public static int								If_Child_Device				= 0;
	// 是否父级设备 0否 1是
	public static int								If_Parent_Device			= 0;
	// 获取子级设备数据信息超时间
	public static int								TimeCount					= 30000;
	// 图片访问路径 // 毫秒
	public static String							HTTP_Path					= "";
	// Session超时时间,单位：分钟
	public static int								SessionTimeOut				= 60
			* 24 * 7;																																																// 60*24*7分钟
	// 是否需要登陆Session // 分钟
	public static int								Login_Session				= 0;
	// 是否需要登陆session的接口需要session验证的接口
	public static Hashtable<String, Integer>		htInterSession				= null;
	// 指定跨域访问IP xxx.xx.xx.xxx 默认为空 // 1需要
	public static String							HttpUrl						= "";
	// 定时器正在运行标签
	public static boolean							bTimeFlag					= false;
	// 定时器正在运行标签
	public static boolean							bTimeBusDataFlag			= false;
	// 编码格式
	public static String							U_CODE						= "UTF-8";
	// 支付相关，参数固定
	public static String							APP_ID						= "xxxx";
	public static String							APP_PRIVATE_KEY				= "xxxx";
	public static String							ALIPAY_PUBLIC_KEY			= "xxxx";
	public static String							AliPay_Check				= "";																																// 支付宝支付确认接口APP
	public static String							AliPay_Check2				= "";																																// 支付宝支付确认接口wap
	public static String							WxPay_Check					= "";																																// 微信支付确认接口
	public static String							Ali_Login					= "";																																// 支付宝授权登陆
	public static String							sub_code					= "8A0731CC39614C90A5D474BC17253713";
	public static String							sub_usercode				= "414A6DB3BBE6419DA3768E6E25127310";
	// 用户登陆或新用户注册接口
	public static String							Is_UserLogin				= "";
	// 需要session验证的接口
	// public static String InterSession = "";
	// 本设备名称
	public static String							S_DESC						= "zxyong我的设备";
	// 是否桌面数据库 0:Mysql 1:sqlite3
	public static int								IL_DB						= 0;																																// 0:Mysql
	// 中间件数据库连接池初始数量 // 1:Sqlite3
	public static int								incrementalConnections		= 2;
	// 中间件数据库连接池最大数量
	public static int								maxConnections				= 15;
	// 老版数采反控插件
	public static String							strYunWei					= "http://xxx.xx.xx.xxx:8089/CenterData?sub_code=8A0731CC39614C90A5D474BC17253713&sub_usercode=414A6DB3BBE6419DA3768E6E25127310";
	// 老版数采MN
	public static String							MN_ID						= "";
	// socket统计
	public static int								socket_count				= 0;
	// 是否启用http协议
	public static boolean							bThread						= true;
	// 存储子设备的IP 和 socket 其中key = clientSocket为本机作为客户端设备socket存储
	public static Hashtable<String, Socket>			htServSockets				= new Hashtable<String, Socket>();
	// 存储子设备的Child_Node 和IP
	public static Hashtable<String, String>			htChildNode					= new Hashtable<String, String>();
	// 存储子设备的Child_Node 和返回值信息
	public static Hashtable<String, String>			htChildInfo					= new Hashtable<String, String>();
	// 存储子设备的Child_Node 和多协议包返回值信息
	public static Hashtable<String, String>			htTempChildInfo				= new Hashtable<String, String>();
	// 连接服务端的客户端socket
	public static Socket							clientSocket				= null;
	// #socket链接的自动链接时间
	public static Hashtable<String, Object[]>		dSockList 				= new Hashtable<String, Object[]>();
	// 向客户端发送SQL执行出错日志信息 0:不发送 1:发送
	public static int								ShowSqlError				= 0;
	public static String							strSessionAva				= "";
	public static int								EncryptUtilType				= 1;																																// 1:SHA1
	// mysql
	// 2:MD5
	// sql
	// server2005
	// 3:sha256加密
	public static String							CustTimeTaskNum				= "";																																// 毫秒为单位，多个定时器用分号隔开
	// 自定义定时器参数
	public static String							CustTimeREFLECT_IN_CLASS	= "";																																// 自定义定时器拦截器，多个拦截器用分号隔开
	// 作为服务端接收数据拦截器
	public static String							ServerREFLECT_IN_CLASS		= "";
	// 作为客户端接收数据拦截器
	public static String							ClientREFLECT_IN_CLASS		= "";
	// 访问父级设备web端口号
	public static int								ServerWebPort				= -1;

	public static List<z_code_element>				liz_code_element			= null;

	public static String							UpLoad_File					= "";
	// MQTT服务器IP tcp://192.168.1.152:61613
	public static String							MQTT_host					= "";																																// "tcp://192.168.1.152:61613";
	// MQTT服务器账号 sysadmin
	public static String							MQTT_username				= "";
	// MQTT服务器密码 1qaz2wsxADMIN
	public static String							MQTT_pwd					= "";
	// MQTT主题推送 发送数据编码以","为分隔符如：A01_MIN,A01_HOUR
	public static String							MQTT_topic_pull				= "";
	// MQTT主题订阅 获取数据编码以","为分隔符如：A01_MIN,A01_HOUR
	public static String							MQTT_topic_get				= "A01_MIN,A01_HOUR";
	// MQTT Client
	public static MqttClient						mqclient					= null;
	// MQTT主题推送TOPIC
	public static Hashtable<String, MqttTopic>		htMqttTopicPull				= new Hashtable<String, MqttTopic>();
	// MQTT主题订阅TOPIC
	public static Hashtable<String, MqttTopic>		htMqttTopicGet				= new Hashtable<String, MqttTopic>();
	// MQTT接收数据拦截器
	public static String							MQTTREFLECT_IN_CLASS		= "";
	public static int								iReturnUppLower				= 0;																																// 返回值字段大小写，0不设置
																																																					// 1大写
																																																					// 2小写
	public static Hashtable<String, String>			ht_T_PARAM_VALUE			= new Hashtable<String, String>();
	public static Hashtable<String, Object[]>		ht_T_DB_CONFIG				= new Hashtable<String, Object[]>();
	public static Hashtable<String, ComDev>			htComPort					= new Hashtable<String, ComDev>();
	// 接口全局缓存开关
	public static int								CachePowerControl			= 0;
	// 接口权限缓存
	public static List<T_SUB_SYS>					lst_T_SUB_SYS				= new ArrayList<T_SUB_SYS>();
	public static List<T_PROC_NAME>					lst_T_PROC_NAME				= new ArrayList<T_PROC_NAME>();
	public static List<T_SUB_POWER>					lst_T_SUB_POWER				= new ArrayList<T_SUB_POWER>();
	public static List<T_SUB_USER>					lst_T_SUB_USER				= new ArrayList<T_SUB_USER>();
	public static List<T_SUB_USERPOWER>				lst_T_SUB_USERPOWER			= new ArrayList<T_SUB_USERPOWER>();

	public static List<T_PROC_INPARAM>				lst_T_PROC_INPARAM			= new ArrayList<T_PROC_INPARAM>();
	public static List<T_PROC_OUTPARAM>				lst_T_PROC_OUTPARAM			= new ArrayList<T_PROC_OUTPARAM>();
	public static List<T_PROC_RETURN>				lst_T_PROC_RETURN			= new ArrayList<T_PROC_RETURN>();
	// webSocket接收数据拦截器
	public static String							WebSocket_IN_CLASS			= "";
	//应用层跨域支持 应用层跨域支持控制 
	//0:不支持跨域请求前后端访问必须IP和端口一致，
	//1:半跨域支持前后端IP一致端口可不一致(如nginx配置前后端分离)；
	//2:完全跨域支持,前后端不同IP不同端口访问均支持;
	public static int 								cdi_access_control_allow_methods = 0;
	//登录失败缓存器 login_id,[请求失败次数,第一次失败时间,锁定时间,IP地址]
	public static Hashtable<String, Object[]>		htLoginFailure				= new Hashtable<String, Object[]>();
	//是否支持单一登录 0:不支持 1:支持
	public static int 							single_login					= 0;	
	
	// 自定义定时器拦截器
	private Com_Para()
	{
	}
	
	public static Com_Para getInstance()
	{
		if(java.util.Objects.equals(instance,null))
		{
			instance = new Com_Para().getNewCom_Para();
		}
		return instance;
	}

	private Com_Para getNewCom_Para()
	{
		Com_Para dc = new Com_Para();
		Ope_DB_Cent od = new Ope_DB_Cent();
		List<T_DB_CONFIG> lds = od.Get_T_DB_CONFIG();

		if(java.util.Objects.equals(Com_Para.htDb,null))
		{
			Com_Para.htDb = new Hashtable<String, T_DB_CONFIG>();
			for(T_DB_CONFIG tdvv: lds)
			{
				Com_Para.htDb.put(String.valueOf(tdvv.getMAIN_ID()),tdvv);
			}
		}
		return dc;
	}
}